package com.ibatis.plugin;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.sql.DataSource;

public class RoutingDataSource implements DataSource{

	private Map<String,DataSource> datasources = new ConcurrentHashMap<String,DataSource>();

	public void put(String key,DataSource datasource){
		datasources.put(key, datasource);
	}
	@Override
	public Connection getConnection() throws SQLException {
		String key = DataSourceHolder.get();
		if(key == null){
			
		}
		DataSource ds = datasources.get(key);
		if(ds == null){
			
		}
		
		return ds.getConnection();
	}

	@Override
	public Connection getConnection(String username, String password)
			throws SQLException {
		String key = DataSourceHolder.get();
		if(key == null){
			
		}
		DataSource ds = datasources.get(key);
		if(ds == null){
			
		}
		
		return ds.getConnection(username,password);
	}
	@Override
	public PrintWriter getLogWriter() throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setLogWriter(PrintWriter out) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setLoginTimeout(int seconds) throws SQLException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getLoginTimeout() throws SQLException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		// TODO Auto-generated method stub
		return false;
	}
	
	
}
